/**
 * Created by Mark on 2018/4/11.
 * 用户个人中心
 */

require("./user-center.css");
require("./user-center-img.css");
require("page/common/nav/nav.js");
require("page/common/header/header.js");
var navSide = require("page/common/nav-side/nav-side.js");
var _user = require("service/user-service.js");
var _mm = require("util/mm.js");
var templateIndex = require("./user-center.string");
var templateUserImage = require("./user-center-img.string");

var page = {
    init : function(){
        this.onLoad();
    },
    //初始化加载的信息
    onLoad : function(){
        navSide.init({//加载侧边导航
            name : "user-center",
        });
        this.loadUserInfo();//加载用户信息
    },
    loadUserInfo : function(){
        var userHtml = "",
            userImageHtml="";

        _user.getUserInfo(
            function(res){//请求成功时的回调函数
                userHtml = _mm.renderHtml(templateIndex,res.data);
                $(".userInfo").html(userHtml);
                userImageHtml = _mm.renderHtml(templateUserImage,res.data);
                $(".user-image").html(userImageHtml);
            },
            function(err){//请求失败时的回调函数
                _mm.errorTips(err.msg);
            }
        );
    }
};

$(function(){
    page.init();
});

